/**
 * Created by dongp on 2018/1/20.
 */
$(function (){
    iniList();
    editResource();
    cancelResource();

});

function iniList() {
    var obj = $("#resourceList").datagrid("getSelected");
    if(Kit.isEmpty(obj)) {
        return false;
    }
    $("#id").val(obj.id);
    $("#resourceName").val(obj.resourceName);
    $("#resourceUrl").val(obj.resourceUrl);
}


function editResource(){

    $("#editResource_save").on("click",function (){
        if(Kit.isEmpty($("#resourceName").val())) {
            $.messager.alert("帮助提示","请输入资源名称");
            return false;
        }
        if(Kit.isEmpty($("#resourceUrl").val())) {
            $.messager.alert("帮助提示","请输入资源url");
            return false;
        }

        var sendData = {
            id:$("#id").val(),
            resourceName:$("#resourceName").val(),
            resourceUrl: $("#resourceUrl").val()
        }

        ui.request({
            url:"/admin/resource/modify",
            data:sendData,
            success:function (rtn) {
                console.log(rtn)
                if(rtn.code != undefined && rtn.code !== "0000"){
                    $.messager.alert(rtn.msg,rtn.desc);
                }
                $('#win').window('close');
                $("#resourceList").datagrid("reload",{});
            }
        })
    });
}

function cancelResource() {
    $("#editResource_cancel").on("click",function (){
        $('#win').window('close');
    });
}